﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HotelManagement
{
    public partial class CustomerSearchFRM : Form
    {
        public string c_fname;
        public string c_lname;
        public int c_id;
        SqlConnection Cnn = new SqlConnection(Globals.DBConnection());
        DataSet ds = new DataSet();
        SqlDataAdapter da;
        
        public CustomerSearchFRM()
        {
            InitializeComponent();
        }

        private void CustomerSearchFRM_Load(object sender, EventArgs e)
        {
            da = new SqlDataAdapter("SELECT c_id AS [شماره مشتری] ,c_fname as [نام] ,c_lname as [نام خانوادگی],c_ncode as [شماره ملی] ,c_phonenumber as [شماره تماس]  from Customer", Cnn);
            da.Fill(ds);
            dGView_Customer.DataSource = ds.Tables[0];
        }

        private void fnameTxt_TextChanged(object sender, EventArgs e)
        {
            da =new SqlDataAdapter("SELECT c_id AS [شماره مشتری] ,c_fname as [نام] ,c_lname as [نام خانوادگی],c_ncode as [شماره ملی] ,c_phonenumber as [شماره تماس]  from Customer WHERE (c_fname LIKE @fname + N'%' OR @fname=N'') AND (c_lname LIKE @lname + N'%' OR @lname=N'') AND (c_ncode LIKE @ncode + N'%' OR @ncode=N'') order by c_id desc",Cnn);
            da.SelectCommand.Parameters.AddWithValue("@fname", fNameSearchTxt.Text);
            da.SelectCommand.Parameters.AddWithValue("@lname", LnameSearchTxt.Text);
            da.SelectCommand.Parameters.AddWithValue("@ncode", NcodeSearchTxt.Text);

            ds.Clear();
            da.Fill(ds);
            dGView_Customer.DataSource = ds.Tables[0];
        }

        private void dGView_Customer_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;

            c_fname = dGView_Customer.CurrentRow.Cells[1].Value.ToString() ;
            c_lname = dGView_Customer.CurrentRow.Cells[2].Value.ToString();
            c_id = (int)dGView_Customer.CurrentRow.Cells[0].Value;
            
        }

    }
}
